<!DOCTYPE html>
<html>
<head>
	<title>可视化编辑</title>
	{load href="__STATIC__/common/js/jquery.min.js" /}
	{load href="__PUBLIC__/plugins/Ueditor/ueditor.config.js" /}
	{load href="__PUBLIC__/plugins/Ueditor/ueditor.all.min.js" /}
	{load href="__PUBLIC__/plugins/Ueditor/lang/zh-cn/zh-cn.js" /}
	{load href="__PUBLIC__/plugins/layer-v3.1.0/layer.js" /}
	{load href="__STATIC__/admin/js/global.js" /}
	<style type="text/css">
		.ncap-form-default {
		    padding: 10px 0;
		    overflow: hidden;
		}
		a {
		    text-decoration: none;
		}
		a.ncap-btn-big {
		    font: bold 14px/20px "microsoft yahei", arial;
		    color: #777;
		    background-color: #ECF0F1;
		    text-align: center;
		    vertical-align: middle;
		    display: inline-block;
		    height: 20px;
		    padding: 7px 19px;
		    border: solid 1px #BEC3C7;
		    border-radius: 3px;
		    cursor: pointer;
		}
		a.ncap-btn-green {
		    background-color: #4fc0e8;
			color: #FFF;
		    text-shadow: 0 -1px 0 rgba(0,0,0,0.10);
		    border-color: #3aa8cf;
		}
		.ckeditor {
			/*height: auto;*/
			/*height: 500px;*/
		}
		.panel-default {
			/*height: 510px;*/
		}
	</style>
</head>
<body>
	<div class="panel panel-default">
		<div class="span12 ckeditor">
			<form class="form-horizontal" id="post_form" onsubmit="return check_submit();">
				<div class="control-group">
					<textarea id="post_content" name="content" title="">{$field.info.value|default=''}</textarea>
				</div>
				<div class="control-group ncap-form-default">
					<div class="controls">
						<input type="hidden" name="id" value="{$field.id|default=''}">
						<input type="hidden" name="type" value="{$field.type|default=''}">
						<input type="hidden" name="page" value="{$field.page|default=''}">
                        <input type="hidden" name="v" value="{$v|default='pc'}">
						<a href="JavaScript:void(0);" onclick="check_submit();" class="ncap-btn-big ncap-btn-green" id="submitBtn">确认提交</a>
					</div>
				</div>
			</form>
		</div>
	  </div>
	</div>
	<script type="text/javascript">
	    var url="{:U('Ueditor/index',array('savepath'=>'ui'))}";
	    var ue = UE.getEditor('post_content',{
	        serverUrl :url,
	        zIndex: 999,
	        initialFrameWidth: "100%", //初化宽度
	        initialFrameHeight: 500, //初化高度            
	        focus: false, //初始化时，是否让编辑器获得焦点true或false
	        maximumWords: 99999,
	        removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign',//允许的最大字符数 'fullscreen',
	        pasteplain:false, //是否默认为纯文本粘贴。false为不使用纯文本粘贴，true为使用纯文本粘贴
	        autoHeightEnabled: false,
	        toolbars: ueditor_toolbars,
	        initialContent: parent.eyou_getOldHtml()
	    });

	    var parentObj = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

        function check_submit()
        {
	        // if(UE.getEditor('post_content').getContent() == ''){
	        //     parent.showErrorMsg('内容不能为空！');
	        //     return false;
	        // }

	        if ($('input[name=id]').val() == '' || $('input[name=id]').val() == undefined || $('input[name=type]').val() == '' || $('input[name=page]').val() == '') {
	            parent.showErrorMsg('缺少系统参数：id、type、page，尝试请求技术支持！');
	            return false;
	        }
            
	        layer_loading('正在处理');
	        $.ajax({
	        	url: "{:U('api/Uiset/submit')}",
	        	type: 'POST',
	        	dataType: 'JSON',
	        	data: $('#post_form').serialize(),
	        	success: function(res){
        			layer.closeAll();
	        		if (res.code == 1) {
	        			parent.layer.msg(res.msg, {shade: 0.3, time: 1000}, function(){
		        			parent.window.location.reload();
		        			parent.layer.close(parentObj);
	        			});
	        		} else {
	        			// parent.showErrorMsg(res.msg);
                		layer.alert(res.msg, {icon:5});
	        		}
                    return false;
	        	},
	        	error: function(e){
        			layer.closeAll();
                    // parent.showErrorMsg('操作失败');
                	layer.alert('操作失败', {icon:5});
                    return false;
	        	}
	        });
        }

	    /**
	     * 封装的加载层
	     */
	    function layer_loading(msg){
	        var loading = layer.msg(
	        msg+'...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请勿刷新页面', 
	        {
	            icon: 1,
	            time: 3600000, //1小时后后自动关闭
	            shade: [0.2] //0.1透明度的白色背景
	        });
	        //loading层
	        var index = layer.load(3, {
	            shade: [0.1,'#fff'] //0.1透明度的白色背景
	        });

	        return loading;
	    }
	</script>
</body>
</html>